home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / gfx / show / gs_src_gs.lha / gs5.03 / opcheck.h < prev    next >
Text File  |  1995-11-29  |  3KB  |  68 lines

  1. /* Copyright (C) 1993, 1995 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* opcheck.h */
  20. /* Operand checking for Ghostscript operators */
  21. /* Requires ialloc.h (for imemory), iref.h, errors.h */
  22.  
  23. /*
  24.  * Check the type of an object.  Operators almost always use check_type,
  25.  * which is defined in oper.h; check_type_only is for checking
  26.  * subsidiary objects obtained from places other than the stack.
  27.  */
  28. #define check_type_only(rf,typ)\
  29.   if ( !r_has_type(&rf,typ) ) return_error(e_typecheck)
  30. #define check_stype_only(rf,styp)\
  31.   if ( !r_has_stype(&rf,imemory,styp) ) return_error(e_typecheck)
  32. /* Check for array */
  33. #define check_array_else(rf,errstat)\
  34.   if ( !r_has_type(&rf, t_array) ) errstat
  35. #define check_array_only(rf)\
  36.   check_array_else(rf, return_error(e_typecheck))
  37. /* Check for procedure.  check_proc_failed includes the stack underflow */
  38. /* check, but it doesn't do any harm in the off-stack case. */
  39. int check_proc_failed(P1(const ref *));
  40. #define check_proc(rf)\
  41.   if ( !r_is_proc(&rf) ) return_error(check_proc_failed(&rf));
  42. #define check_proc_only(rf) check_proc(rf)
  43.  
  44. /* Check for read, write, or execute access. */
  45. #define check_access(rf,acc1)\
  46.   if ( !r_has_attr(&rf,acc1) ) return_error(e_invalidaccess)
  47. #define check_read(rf) check_access(rf,a_read)
  48. #define check_write(rf) check_access(rf,a_write)
  49. #define check_execute(rf) check_access(rf,a_execute)
  50. #define check_type_access_only(rf,typ,acc1)\
  51.   if ( !r_has_type_attrs(&rf,typ,acc1) )\
  52.     return_error((!r_has_type(&rf,typ) ? e_typecheck : e_invalidaccess))
  53. #define check_read_type_only(rf,typ)\
  54.   check_type_access_only(rf,typ,a_read)
  55. #define check_write_type_only(rf,typ)\
  56.   check_type_access_only(rf,typ,a_write)
  57.  
  58. /* Check for an integer value within an unsigned bound. */
  59. #define check_int_leu(orf, u)\
  60.   check_type(orf, t_integer);\
  61.   if ( (ulong)(orf).value.intval > (u) ) return_error(e_rangecheck)
  62. #define check_int_leu_only(rf, u)\
  63.   check_type_only(rf, t_integer);\
  64.   if ( (ulong)(rf).value.intval > (u) ) return_error(e_rangecheck)
  65. #define check_int_ltu(orf, u)\
  66.   check_type(orf, t_integer);\
  67.   if ( (ulong)(orf).value.intval >= (u) ) return_error(e_rangecheck)
  68.